<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加载动画</title>
    <style>
        body{
            padding: 0;
            margin: 0;
            height: 100vh;
            width: 100vw;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        /* #canvas{
            background-color: #fff;
        } */
    </style>
</head>
<body>
    <canvas id="canvas" width="300" height="300"></canvas>

    <script>
        let canvas = document.getElementById('canvas');
        let ctx = canvas.getContext('2d')
        let times = 0;
        function drawLoding(time)
        {
            ctx.clearRect(0,0,300,300)
            for (let index = 0; index < 18; index++) {
                let opacity = 18+index + 1 - time<=18?(18+index + 1 - time)/18:(18+index + 1 - time)%18/18;
                ctx.save();
                ctx.fillStyle = `rgba(193, 44, 31,${opacity})`;
                ctx.translate(150,150);
                ctx.rotate(index*20*Math.PI/180);
                ctx.beginPath();
                ctx.arc(0,120,15,0,360*Math.PI/180,false);
                ctx.closePath();
                ctx.fill();
                ctx.restore();
            }
            ctx.save();
            let txtOpacity = time>9?(18-time)/9:time/9;
            ctx.font="bold 20px Fira Code Light"
            ctx.fillStyle = `rgb(193, 44, 31,${txtOpacity})`;
            ctx.fillText('LOADING...',100,160)
        }
        drawLoding(0);

        setInterval(() => {
            if(times>=18)
            {
                times=0
            }
            times++;
            drawLoding(times);
        }, 100);
    </script>
</body>
</html>